package com.taotao.manage.controller.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.manage.pojo.Item;
import com.taotao.manage.service.ItemService;

@Controller
@RequestMapping("api/item")
public class ApiItemController {

	@Autowired
	private ItemService itemService;

	/**
	 * 根据id查询商品详情
	 * @param id
	 * @return
	 */
	@GetMapping("{id}")
	public ResponseEntity<Item> queryItemById(@PathVariable("id")Long id){
		try {
			if(id == null || id.longValue() <= 0){
				return ResponseEntity.badRequest().build();
			}
			Item item = this.itemService.queryById(id);
			if(item == null){
				return ResponseEntity.notFound().build();
			}
			return ResponseEntity.ok(item);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
	}
}
